package cn.com.wxd.action;

/**
 * 自定义验证框架返回结果
 * Created by ComXu on 2017/5/19.
 */
public class ValidatorResult {
    private ValidatorResult(Integer resNo, String message) {
        this.resNo = resNo;
        this.message = message;
    }

    private ValidatorResult(Integer resNo) {
        this.resNo = resNo;
        this.message = "";
    }
    public ValidatorResult(){}

    private static final Integer FAILURE = -1;
    private static final Integer SUCCESS = 0;

    private int resNo;
    private String message;

    /**
     * 失败的结果
     *
     * @param message
     *
     * @return
     */
    protected static ValidatorResult failuerValidatorResult(String message) {
        return new ValidatorResult(ValidatorResult.FAILURE, message);
    }

    /**
     * 成功的结果
     *
     * @return
     */
    protected static ValidatorResult successValidatorResult() {
        return new ValidatorResult(ValidatorResult.SUCCESS);
    }

    /**
     * 验证是否成功
     *
     * @return
     */
    public boolean isSuccess() {
        return resNo == 0;
    }

    /**
     * 验证是否失败
     *
     * @return
     */
    public boolean isFailure() {
        return resNo == -1;
    }

    public String getMessage() {
        return message;
    }
}
